<?php
defined('BY_JYA') or exit('error');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'fankuitype'=>intval($_RQ['fankuitype']));
	$params2=array('fromstoreid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']);
	if($_RQ['title']){
		$params2['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$yonghus=pdo_getall('jy_yxw_yonghu',$params2,array('id'),'id');
	if($yonghus){
		$yonghus=array_keys($yonghus);
	}else{
		$yonghus=-1;
	}
	$params['yonghuid']=$yonghus;
	if($_RQ['id']){
		$params['yonghuid']=intval($_RQ['id']);
		$return['params']['id'] =intval($_RQ['id']);
	}
	$orderby=array();
	$pindex = max(1, intval($_RQ['page']));
	if($_RQ['num']){
		$psize = $_RQ['num'];
	}else{
		$psize = 10;
	}
	$total='';
	$list=pdo_getslice('jy_yxw_fankui_log',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=$this->model('yonghu')->member_show($item['yonghuid']);
			$info=pdo_get('jy_yxw_yonghu',array('id'=>$item['yonghuid'],'uniacid'=>$_SESSION['uniacid']));
			$item['classid']=$info['classid'];
			$item['title']=$info['title'];
		}
	}
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'售后反馈跟进'),
		),
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'member','title'=>'用户信息','type'=>'member'),
			array('name'=>'classid','title'=>'所属售后群','type'=>'select','options'=>'class'),
			array('name'=>'workerid','title'=>'跟进员工','type'=>'select','options'=>'workers'),
			array('name'=>'fankuitype','title'=>'跟进类型','type'=>'radio','options'=>'fankui_type'),
			array('type'=>'string','title'=>'跟进内容','name'=>'remark'),
			array('name'=>'createtime','title'=>'日期','type'=>'time'),
		),'action'=>array(
			array('type'=>'href','action'=>'/yonghu.fankui_log/edit/','title'=>'编辑'),
		)),
		'search'=>array(
			array('name'=>'title','width'=>10,'title'=>'售后姓名','type'=>'string'),
		),
	);
	$return['class']=$this->getall('class',array('storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');	
	$return['workers']=$this->getall('worker',array('juese'=>array(9,10,11,12,13),'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');	
	$return['htmls']=$htmls;
	$return['fankui_type']=$this->fankui_type;
	exi($return);
}
if($_RQ['op']=='export'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$params2=array('fromstoreid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']);
	if($_RQ['title']){
		$params2['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$yonghus=pdo_getall('jy_yxw_yonghu',$params2,array('id'),'id');
	if($yonghus){
		$yonghus=array_keys($yonghus);
	}else{
		$yonghus=-1;
	}
	$params['yonghuid']=$yonghus;
	if($_RQ['id']){
		$params['yonghuid']=intval($_RQ['id']);
		$return['params']['id'] =intval($_RQ['id']);
	}
	$params['listid']=$this->session('listid');
	
	$list=pdo_getall('jy_yxw_fankui_log',$params,$fields);
	if($list){
		foreach($list as &$item){
			$item['member']=$this->model('yonghu')->member_show($item['yonghuid']);
			$info=pdo_get('jy_yxw_yonghu',array('id'=>$item['yonghuid'],'uniacid'=>$_SESSION['uniacid']));
			$item['title']=$info['title'];
			$item['classtitle']=pdo_getcolumn('jy_yxw_class',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['classid']),'title');
			$item['worker']=pdo_getcolumn('jy_yxw_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['workerid']),'title');
			$item['fankuitype']=$this->fankui_type[$item['type']];
		}
	}
	$header=array(
		'title'=>'售后姓名',
		'classtitle'=>'售后群',
		'worker'=>'跟进员工',
		'fankuitype'=>'跟进类型',
		'remark'=>'跟进内容',
		'createtime'=>'日期',
	);
	model('core/tools')->export2excel($header,$list,'跟进表');
}